package com.ruoyi.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.business.Complain;
import com.ruoyi.business.MyPage;
import com.ruoyi.business.PageConfig;
import com.ruoyi.business.mapper.ComplainMapper;
import com.ruoyi.business.qo.ComplainQO;
import com.ruoyi.common.common.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @title: UserService
 * @copyright: copyright (c) 2021
 * @author: jiangguanjun
 * @date: 2023/2/8 12:55
 * @firstReview:
 * @lastReview:
 * @desc: 用户相关
 */
@Slf4j
@Component
public class ComplainService {

    @Autowired
    private ComplainMapper complainMapper;



    public ResultBody<IPage<Complain>> queryByPage(ComplainQO complainQO) {
        MyPage myPage = PageConfig.getPage() ;
        Page<Complain> page = new Page<>(myPage.getPageNum(),myPage.getPageSize()) ;
        IPage<Complain> iPage = complainMapper.queryPage(page,complainQO) ;
        List<Complain> complains = iPage.getRecords() ;
        if(CollectionUtils.isEmpty(complains)){
            return ResultBody.success(iPage) ;
        }

        iPage = iPage.setRecords(complains) ;

        return ResultBody.success(iPage) ;
    }

    public Integer deal(Integer deal,Integer id) {
        Complain complain = new Complain() ;
        complain.setDeal(deal);
        complain.setId(id);

        return complainMapper.updateByPrimaryKeySelective(complain) ;
    }
}
